/**
 @file ctc_chip_cli.c

 @date 2020-07-09

 @version v2.0

---file comments----
*/

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "api/include/ctcs_api.h"
#include "ctc_common.h"
#include "ctc_chip.h"
#include "ctc_chip_cli.h"

struct ctc_monitor_task_s
{
    sal_task_t* monitor_task;
    uint8 task_end;
};
typedef struct ctc_monitor_task_s ctc_monitor_task_t;
ctc_monitor_task_t monitor_polling_task;

struct ctc_chip_write_file_s
{
    uint16 interval;
    uint16 serdes_id;
    char file[MAX_FILE_NAME_SIZE];
    ctc_vti_t* p_vty;
};
typedef struct ctc_chip_write_file_s ctc_chip_write_file_t;
#define MAX_SERDES_NUM 16

extern int32
_ctc_chip_serdes_read(uint8 lchip, uint8 serdes_id, uint32 address, uint16* p_value16);
extern int32
_ctc_chip_serdes_write(uint8 lchip, uint8 serdes_id, uint32 address, uint16 value16);

#ifdef ASW_ALONE
const char *ctc_get_error_desc(int32 error_code)
{
    static char  error_desc[256+1] = {0};

    switch(error_code)
    {
        case CTC_E_NONE:
          return "NO error ";
        case CTC_E_INVALID_PTR:
          return "Invalid pointer ";
        case CTC_E_INVALID_PORT:
          return "Invalid port ";
        case CTC_E_INVALID_PARAM:
          return "Invalid parameter ";
        case CTC_E_BADID:
          return "Invalid identifier ";
        case CTC_E_INVALID_CHIP_ID:
          return "Invalid chip ";
        case CTC_E_INVALID_CONFIG:
          return "Invalid configuration ";
        case CTC_E_EXIST:
          return "Entry exists ";
        case CTC_E_NOT_EXIST:
          return "Entry not found ";
        case CTC_E_NOT_READY:
          return "Not ready to configuration ";
        case CTC_E_IN_USE:
          return "Already in used ";
        case CTC_E_NOT_SUPPORT:
          return "API or some feature is not supported ";
        case CTC_E_NO_RESOURCE:
          return "No resource in ASIC ";
        case CTC_E_PROFILE_NO_RESOURCE:
          return "Profile no resource in ASIC ";
        case CTC_E_NO_MEMORY:
          return "No memory ";
        case CTC_E_HASH_CONFLICT:
          return "Hash Conflict ";
        case CTC_E_NOT_INIT:
          return "Feature not initialized ";
        case CTC_E_INIT_FAIL:
          return "Feature initialize fail ";
        case CTC_E_DMA:
          return "DMA error ";
        case CTC_E_HW_TIME_OUT:
          return "HW operation timed out ";
        case CTC_E_HW_BUSY:
          return "HW busy ";
        case CTC_E_HW_INVALID_INDEX:
          return "Exceed max table index ";
        case CTC_E_HW_NOT_LOCK:
          return "HW not lock ";
        case CTC_E_HW_FAIL:
          return "HW operation fail ";
        case CTC_E_VERSION_MISMATCH:
          return "Version mismatch";
        case CTC_E_PARAM_CONFLICT:
          return "Parameter Conflict";
        case CTC_E_TOO_MANY_FRAGMENT:
          return "Too many fragment, need Defragmentation";
        case CTC_E_WB_BUSY:
          return "Warmboot busy ";

    default:
      sal_sprintf(error_desc,"Error code:%d",error_code);
      return error_desc;
    }

}
#endif

CTC_CLI(ctc_cli_asw_chip_show_chip_clock,
        ctc_cli_asw_chip_show_chip_clock_cmd,
        "show chip clock frequence",
        "show",
        "chip",
        "clock",
        "frequence")
{
    int32 ret = CLI_SUCCESS;
    uint16 freq = 0;


    ret = ctcs_get_chip_clock(g_api_lchip, &freq);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("The chip clock freq is: %dM\n", freq);

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_show_mac_led_clock_frequency,
        ctc_cli_asw_chip_show_mac_led_clock_frequency_cmd,
        "show chip mac-led freq",
        "Show",
        "Chip module",
        "Mac led",
        "Mac led blink interval")
{
    int32 ret       = CLI_SUCCESS;
    void* value = 0;
    uint8 type = 0;
    ctc_chip_peri_clock_t peri_clock;

    sal_memset(&peri_clock, 0, sizeof(ctc_chip_peri_clock_t));

    peri_clock.type = CTC_CHIP_PERI_MAC_LED_TYPE;
    type = CTC_CHIP_PROP_PERI_CLOCK;
    value = &peri_clock;

    ret = ctcs_chip_get_property(g_api_lchip, type, value);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("Mac led clock frequency is %d Khz \n", peri_clock.clock_val);

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_show_gport_property_prop,
        ctc_cli_asw_chip_show_gport_property_prop_cmd,
        "show chip property serdes-to-gport SERDES",
        "Show operate",
        "Chip module",
        "property",
        "Serdes id to gport",
        "Serdes Id Value")
{
    ctc_port_serdes_info_t serdes_port;
    int32 ret = 0;

    sal_memset(&serdes_port, 0, sizeof(ctc_port_serdes_info_t));

    CTC_CLI_GET_UINT8_RANGE("serdes-to-gport", serdes_port.serdes_id,  argv[0], 0, CTC_MAX_UINT8_VALUE);

    ctc_cli_out("Show Serdes                        :  0x%04x\n", serdes_port.serdes_id);
    ctc_cli_out("-------------------------------------------\n");

    ret = ctcs_chip_get_property(g_api_lchip, CTC_CHIP_PROP_SERDES_ID_TO_GPORT, (void*)&serdes_port);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("%-34s:  0x%04x\n", "Gport", serdes_port.gport);
    ctc_cli_out("%-34s:  %u\n", "serdes mode", serdes_port.serdes_mode);

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_chip_set_serdes_loopback,
        ctc_cli_asw_chip_set_serdes_loopback_cmd,
        "chip serdes SERDES loopback (internal|external) (enable|disable)",
        "chip module",
        "Serdes",
        "Serdes id",
        "Loopback parameter",
        "Internal loopback",
        "External loopback",
        "Enable",
        "Disable")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_loopback_t  lb_param;
    uint8 serdes_id = 0;
    uint8 index = 0;

    sal_memset(&lb_param, 0, sizeof(ctc_chip_serdes_loopback_t));

    CTC_CLI_GET_UINT8_RANGE("serdes", serdes_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    lb_param.serdes_id = serdes_id;

    index = CTC_CLI_GET_ARGC_INDEX("internal");
    if (0xFF != index)
    {
        lb_param.mode = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("external");
    if (0xFF != index)
    {
        lb_param.mode = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("disable");
    if (0xFF != index)
    {
        lb_param.enable = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        lb_param.enable = 1;
    }

    ret = ctcs_chip_set_property(g_api_lchip, CTC_CHIP_PROP_SERDES_LOOPBACK, (void*)&lb_param);
    if(ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;

}

CTC_CLI(ctc_cli_asw_chip_serdes_prbs,
        ctc_cli_asw_chip_serdes_prbs_cmd,
        "chip serdes SERDES (prbs (tx|rx) (enable mode VALUE | disable))",
        "Chip module",
        "Serdes",
        "Serdes ID",
        "Pseudo random binary sequence",
        "Transmit prbs pattern",
        "Receive prbs pattern and check",
        CTC_CLI_ENABLE,
        "Pattern mode",
        "0-PRBS7_PLUS, 6-PRBS31_PLUS",
        CTC_CLI_DISABLE)
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_prbs_t prbs_param;
    uint8 serdes_id = 0;
    uint8 index = 0;

    sal_memset(&prbs_param, 0, sizeof(ctc_chip_serdes_prbs_t));

    CTC_CLI_GET_UINT8_RANGE("serdes", serdes_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    prbs_param.serdes_id = serdes_id;

    /* prbs cfg */
    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        prbs_param.value = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("disable");
    if (0xFF != index)
    {
        prbs_param.value = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("rx");
    if (0xFF != index)
    {
        prbs_param.mode = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("tx");
    if (0xFF != index)
    {
        prbs_param.mode = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("mode", prbs_param.polynome_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    ret = ctcs_chip_set_property(g_api_lchip, CTC_CHIP_PROP_SERDES_PRBS, (void*)&prbs_param);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    index = CTC_CLI_GET_ARGC_INDEX("rx");
    if (0xFF != index)
    {
        ctc_cli_out("%d\n",prbs_param.value);
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_serdes_ffe_param,
        ctc_cli_asw_chip_serdes_ffe_param_cmd,
        "chip serdes SERDES ffe ({c2 VALUE|c3 VALUE} (trace-len (0inch|10inch|20inch)|))",
        "chip module",
        "serdes",
        "serdes id",
        "ffe parameter",
        "coefficient2",
        "coefficient2 VALUE",
        "coefficient3",
        "coefficient3 VALUE",
        "Trace length",
        "0~10inch",
        "10~20inch",
        ">=20inch")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_ffe_t  ffe_param;
    uint8 serdes_id = 0;
    uint8 index = 0;
    int16 coefficient[CTC_CHIP_FFE_PARAM_NUM];
    sal_memset(&ffe_param, 0, sizeof(ctc_chip_serdes_ffe_t));
    sal_memset(coefficient, 0, sizeof(int16)*CTC_CHIP_FFE_PARAM_NUM);

    CTC_CLI_GET_UINT8_RANGE("serdes", serdes_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    ffe_param.serdes_id = serdes_id;

    index = CTC_CLI_GET_ARGC_INDEX("0inch");
    if (0xFF != index)
    {
        ffe_param.trace_len = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("10inch");
    if (0xFF != index)
    {
        ffe_param.trace_len = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("20inch");
    if (0xFF != index)
    {
        ffe_param.trace_len = 2;
    }

    index = CTC_CLI_GET_ARGC_INDEX("c2");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("c2", ffe_param.coefficient[2], argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("c3");
    if (index != 0xFF)
    {
       CTC_CLI_GET_UINT16("c3", ffe_param.coefficient[3], argv[index + 1]);
    }

    ret = ctcs_chip_set_property(g_api_lchip, CTC_CHIP_PROP_SERDES_FFE, (void*)&ffe_param);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_get_serdes_prop,
        ctc_cli_asw_chip_get_serdes_prop_cmd,
        "show chip serdes SERDES (loopback|ffe | prbs (rx|tx))",
        "Show operate",
        "Chip module",
        "Serdes",
        "Serdes id",
        "Loopback",
        "FFE parameter",
        "PRBS",
        "Rx",
        "Tx")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_loopback_t lb_param;
    uint8 serdes_id = 0;
    uint8 index = 0;
    uint8 type = 0;
    uint8 temp = 0;

    CTC_CLI_GET_UINT8_RANGE("serdes", serdes_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    ctc_cli_out("Show Serdes                            :  0x%x\n", serdes_id);
    ctc_cli_out("-------------------------------------------\n");

    index = CTC_CLI_GET_ARGC_INDEX("loopback");
    if (0xFF != index)
    {
        sal_memset(&lb_param, 0, sizeof(ctc_chip_serdes_loopback_t));
        type = CTC_CHIP_PROP_SERDES_LOOPBACK;
        lb_param.serdes_id = serdes_id;
        lb_param.mode = 0;

        ret = ctcs_chip_get_property(g_api_lchip, type, (void*)&lb_param);
        if (ret < 0)
        {
            temp = 0xff;
        }
        else
        {
            temp = lb_param.enable;
        }

        lb_param.mode = 1;
        ret = ctcs_chip_get_property(g_api_lchip, type, (void*)&lb_param);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        ctc_cli_out("%-34s:  %c\n", "Internal Loopback", (0xff==temp)?'-':(temp+'0'));
        ctc_cli_out("%-34s:  %u\n", "External Loopback", lb_param.enable);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ffe");
    if (0xFF != index)
    {
        ctc_chip_serdes_ffe_t ffe_param;
        sal_memset(&ffe_param, 0, sizeof(ctc_chip_serdes_ffe_t));
        ffe_param.serdes_id = serdes_id;

        ret = ctcs_chip_get_property(g_api_lchip, CTC_CHIP_PROP_SERDES_FFE, (void*)&ffe_param);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        ctc_cli_out("%s%-34d:  %d\n", "FFE C",2, ffe_param.coefficient[2]);
        ctc_cli_out("%s%-34d:  %d\n", "FFE C",3, ffe_param.coefficient[3]);
        ctc_cli_out("%s%-30s:  %d\n", "TRACE_LEN", " ", ffe_param.trace_len);
    }

    index = CTC_CLI_GET_ARGC_INDEX("prbs");
    if (0xFF != index)
    {
        ctc_chip_serdes_prbs_t prbs_param;
        sal_memset(&prbs_param, 0, sizeof(ctc_chip_serdes_prbs_t));
        type = CTC_CHIP_PROP_SERDES_PRBS;
        prbs_param.serdes_id = serdes_id;

        index = CTC_CLI_GET_ARGC_INDEX("rx");
        if (0xFF != index)
        {
            prbs_param.mode = 0;
        }

        index = CTC_CLI_GET_ARGC_INDEX("tx");
        if (0xFF != index)
        {
            prbs_param.mode = 1;
        }

        ret = ctcs_chip_get_property(g_api_lchip, type, (void*)&prbs_param);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        ctc_cli_out("%-34s:  %u\n", "Polynome_type", prbs_param.polynome_type);
        ctc_cli_out("%-34s:  %u\n", "Error_cnt", prbs_param.error_cnt);
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_write_serdes,
        ctc_cli_asw_chip_write_serdes_cmd,
        "chip serdes SERDES write ADDR_OFFSET VALUE",
        "chip module",
        "serdes",
        "serdes id",
        "Write",
        "Address offset",
        "Value")
{
    int32 ret       = CLI_SUCCESS;
    uint8 serdes_id = 0;
    uint16 address = 0;
    uint16 value16 = 0;

    CTC_CLI_GET_UINT8("serdes", serdes_id, argv[0]);
    CTC_CLI_GET_UINT16("address offset", address, argv[1]);
    CTC_CLI_GET_UINT16("value", value16, argv[2]);

    ret = _ctc_chip_serdes_write(g_api_lchip, serdes_id, address, value16);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_read_serdes,
        ctc_cli_asw_chip_read_serdes_cmd,
        "chip serdes SERDES read ADDR_OFFSET",
        "Chip module",
        "Serdes",
        "Serdes id",
        "Read",
        "Address offset")
{
    int32 ret       = CLI_SUCCESS;
    uint8 serdes_id = 0;
    uint16 address = 0;
    uint16 value16 = 0;

    CTC_CLI_GET_UINT8("serdes", serdes_id, argv[0]);
    CTC_CLI_GET_UINT16("address offset", address, argv[1]);

    ret = _ctc_chip_serdes_read(g_api_lchip, serdes_id, address, &value16);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("Read data:0x%04x\n", value16);

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_set_ipmc_config,
        ctc_cli_asw_chip_set_ipmc_config_cmd,
        "chip global-cfg ipmc-property l2mc ENABLE",
        "Chip module",
        "Global config",
        "Ipmc property",
        "IP based l2mc",
        "If set,ip base L2MC lookup")
{
    int32 ret = CLI_SUCCESS;
    ctc_global_ipmc_property_t property;

    sal_memset(&property, 0, sizeof(ctc_global_ipmc_property_t));
    CTC_CLI_GET_UINT8("value", property.ip_l2mc_mode, argv[0]);

    ret = ctcs_global_ctl_set(g_api_lchip, CTC_GLOBAL_IPMC_PROPERTY, &property);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;

}

CTC_CLI(ctc_cli_asw_chip_show_ipmc_config,
        ctc_cli_asw_chip_show_ipmc_config_cmd,
        "show chip global-cfg ipmc-property",
        "Show",
        "Chip module",
        "Global config",
        "Ipmc property")
{
    int32 ret = CLI_SUCCESS;
    ctc_global_ipmc_property_t property;

    sal_memset(&property, 0, sizeof(ctc_global_ipmc_property_t));
    ret = ctcs_global_ctl_get(g_api_lchip, CTC_GLOBAL_IPMC_PROPERTY, &property);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("Show chip global-cfg ipmc info\n");
    ctc_cli_out("==============================\n");
    ctc_cli_out("l2mc mode : %d\n", property.ip_l2mc_mode);
    ctc_cli_out("==============================\n");

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_set_acl_config,
        ctc_cli_asw_chip_set_acl_config_cmd,
        "chip global-cfg acl-property { mac-sel-da | ipv6-sa-addr-mode VALUE | ipv6-da-addr-mode VALUE \
                                       | mac-ipv6-add1-mode VALUE | mac-ipv6-add2-mode VALUE  }",
        "Chip module",
        "Global config",
        "Acl property",
        "Mac-ext key sel da as mac addr",
        "Ipv6 sa encode mode","mode value: 0-sip[31,0], 1-sip[63,32], 2-sip[95,64], 3-sip[128,96]",
        "Ipv6 da encode mode","mode value: 0-dip[31,0], 1-dip[63,32], 2-dip[95,64], 3-dip[128,96]",
        "key field ipaddr1 64bit addr mode", "mode value: 0-ipv6 sa[63:0], 1-ipv6 da[63:0] ",
        "key field ipaddr2 64bit addr mode", "mode value: 0-ipv6 sa[128:64], 1-ipv6 da[128:64] ")
{
    int32 ret = CLI_SUCCESS;
    ctc_global_acl_property_t property;
    uint8 index = 0;

    sal_memset(&property, 0, sizeof(ctc_global_acl_property_t));

    ctcs_global_ctl_set(g_api_lchip, CTC_GLOBAL_IPMC_PROPERTY, &property);


    if(0xff != CTC_CLI_GET_ARGC_INDEX("mac-sel-da"))
    {
        property.l2l3_key_u2_mode = 1;
    }
    index = CTC_CLI_GET_ARGC_INDEX("ipv6-da-addr-mode");
    if(index != 0xff)
    {
        CTC_CLI_GET_UINT8("value", property.key_ipv6_da_addr_mode, argv[index+1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ipv6-sa-addr-mode");
    if(index != 0xff)
    {
        CTC_CLI_GET_UINT8("value", property.key_ipv6_sa_addr_mode, argv[index+1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("mac-ipv6-add1-mode");
    if(index != 0xff)
    {
        CTC_CLI_GET_UINT8("value", property.mac_ipv6_key_u0_mode, argv[index+1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("mac-ipv6-add2-mode");
    if(index != 0xff)
    {
        CTC_CLI_GET_UINT8("value", property.mac_ipv6_key_u1_mode, argv[index+1]);
    }
    
    ret = ctcs_global_ctl_set(g_api_lchip, CTC_GLOBAL_ACL_PROPERTY, &property);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_show_acl_config,
        ctc_cli_asw_chip_show_acl_config_cmd,
        "show chip global-cfg acl-property",
        "Show",
        "Chip module",
        "Global config",
        "acl property")
{
    int32 ret = CLI_SUCCESS;
    ctc_global_acl_property_t property;

    sal_memset(&property, 0, sizeof(ctc_global_acl_property_t));
    ret = ctcs_global_ctl_get(g_api_lchip, CTC_GLOBAL_ACL_PROPERTY, &property);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("Show chip global-cfg acl info\n");
    ctc_cli_out("==============================\n");
    ctc_cli_out("Mac-udf mac add : %s\n", property.l2l3_key_u2_mode ? "mac-da" : "mac-sa");
    ctc_cli_out("Ipv6 sa encode mode : %d\n", property.key_ipv6_sa_addr_mode);
    ctc_cli_out("Ipv6 da encode mode : %d\n", property.key_ipv6_da_addr_mode);
    ctc_cli_out("Ipaddr1 64bit  mode : %d\n", property.mac_ipv6_key_u0_mode);
    ctc_cli_out("Ipaddr2 64bit  mode : %d\n", property.mac_ipv6_key_u1_mode);
    ctc_cli_out("==============================\n");

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_mdio_read,
            ctc_cli_asw_chip_mdio_read_cmd,
            "chip read mdio (bus-id ID phy-id ID reg-addr ADDR)",
            "Chip module",
            "Read operate",
            "Mdio bus",
            "Bus id",
            "MDIO bus ID",
            "Phy number",
            "ID",
            "Register address",
            "ADDR")
{
    int32 ret = 0;
    uint8 index = 0xFF;
    ctc_chip_mdio_type_t type = CTC_CHIP_MDIO_GE;
    ctc_chip_mdio_para_t mdio_para = {0};

    index = CTC_CLI_GET_ARGC_INDEX("bus-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("bus-id", mdio_para.bus, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("phy-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("phy-id", mdio_para.phy_addr, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("reg-addr");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("reg-addr", mdio_para.reg, argv[index + 1]);
    }

    ret = ctcs_chip_mdio_read(g_api_lchip, type,  &mdio_para);

    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }


    ctc_cli_out("PHY addr: 0x%x\treg: 0x%x\tvalue: 0x%x\n", mdio_para.phy_addr,mdio_para.reg, mdio_para.value);

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_asw_chip_mdio_write,
            ctc_cli_asw_chip_mdio_write_cmd,
            "chip write mdio (bus-id ID phy-id ID reg-addr ADDR value VAL)",
            "Chip module",
            "Write operate",
            "Mdio bus",
            "bus id",
            "<0 - 1>",
            "Phy number",
            "ID",
            "Register address",
            "ADDR",
            "Value",
            "VALUE")
{
    int32 ret = 0;
    uint8 index = 0xFF;
    ctc_chip_mdio_type_t type = CTC_CHIP_MDIO_GE;
    ctc_chip_mdio_para_t mdio_para = {0};

    index = CTC_CLI_GET_ARGC_INDEX("bus-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("bus-id", mdio_para.bus, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("phy-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("phy-id", mdio_para.phy_addr, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("reg-addr");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("reg-addr", mdio_para.reg, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("value");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("value", mdio_para.value, argv[index + 1]);
    }

    ret = ctcs_chip_mdio_write(g_api_lchip, type,  &mdio_para);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_chip_mac_led_en,
        ctc_cli_asw_chip_mac_led_en_cmd,
        "chip mac-led (enable | disable)",
        "Chip module",
        "Mac led",
        "Enable",
        "Disable")
{
    int32 ret       = CLI_SUCCESS;
    bool enable;

    if (CLI_CLI_STR_EQUAL("enable", 0))
    {
        enable = TRUE;
    }
    else
    {
        enable = FALSE;
    }

    ret = ctcs_chip_set_mac_led_en(g_api_lchip, enable);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_mac_led_mode,
        ctc_cli_asw_chip_mac_led_mode_cmd,
        "chip mac-led para port-id PORT_ID mode MODE {(polarity POLARITY) | ((first-mode FISRT_MODE) (sec-mode SEC_MODE |)) |}",
        "Chip module",
        "Mac led ",
        "Parameter",
        "Port id",
        "Mac id or Lport",
        "mac led mode",
        "<0-1>",
        "polarity",
        "polarity value",
        "first led mode",
        "first mode value",
        "second led mode",
        "second mode value")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_led_para_t led_para;
    ctc_chip_mac_led_type_t led_type;
    uint8 index = 0;

    sal_memset(&led_para, 0, sizeof(ctc_chip_led_para_t));

    CTC_CLI_GET_UINT32("gport", led_para.port_id, argv[0]);

    CTC_CLI_GET_UINT32_RANGE("mode", led_type, argv[1], 0, CTC_MAX_UINT32_VALUE);
    index = CTC_CLI_GET_ARGC_INDEX("polarity");
    if (index != 0xFF)
    {
        if (index + 1 >= argc)
        {
            ctc_cli_out("%% Insufficient  param \n\r");
            return CLI_ERROR;
        }
        CTC_CLI_GET_UINT32_RANGE("polarity", led_para.polarity, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        led_para.op_flag |= CTC_CHIP_LED_POLARITY_SET_OP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("first-mode");
    if (index != 0xFF)
    {
        if (index + 1 >= argc)
        {
            ctc_cli_out("%% Insufficient  param \n\r");
            return CLI_ERROR;
        }

        CTC_CLI_GET_UINT32_RANGE("first-mode", led_para.first_mode, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        led_para.op_flag |= CTC_CHIP_LED_MODE_SET_OP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("sec-mode");
    if (index != 0xFF)
    {
        if (index + 1 >= argc)
        {
            ctc_cli_out("%% Insufficient  param \n\r");
            return CLI_ERROR;
        }

        CTC_CLI_GET_UINT32_RANGE("sec-mode", led_para.sec_mode, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        led_para.op_flag |= CTC_CHIP_LED_MODE_SET_OP;
    }

    led_para.lport_en = 1;

    ret = ctcs_chip_set_mac_led_mode(g_api_lchip, &led_para, led_type);

    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;

}

CTC_CLI(ctc_cli_asw_chip_mac_led_clock_frequency,
        ctc_cli_asw_chip_mac_led_clock_frequency_cmd,
        "chip mac-led (freq FREQ |)",
        "Chip module",
        "Mac led",
        "Mac led clock frequency",
        "frequency value(K)")
{
    int32 ret       = CLI_SUCCESS;
    uint16 freq = 0;
    uint8 index = 0;
    void* value = 0;
    ctc_chip_peri_clock_t peri_clock;
    uint8 type = 0;
    sal_memset(&peri_clock, 0, sizeof(ctc_chip_peri_clock_t));

    index = CTC_CLI_GET_ARGC_INDEX("freq");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("freq-id", freq, argv[index + 1]);
        peri_clock.type = CTC_CHIP_PERI_MAC_LED_TYPE;
        peri_clock.clock_val = freq;
        type = CTC_CHIP_PROP_PERI_CLOCK;
        value = &peri_clock;
    }

    ret = ctcs_chip_set_property(g_api_lchip, type, value);

    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_mac_led_mapping_set,
        ctc_cli_asw_mac_led_mapping_set_cmd,
        "chip led mapping (lport LPORT) (end|)",
        "Chip module",
        "Mac led mapping",
        "Mapping table",
        "Lport list",
        "Port id",
        "End of para")
{
    uint8 index = 0;
    static uint8 loop = 0;
    int32 ret = CLI_SUCCESS;
    static ctc_chip_mac_led_mapping_t led_mapping_rst;
    uint32 max_port_num = 0;
    uint8 is_end = 0;

    max_port_num = MAX_PORT_NUM_PER_CHIP;
    if (ret < 0 )
    {
        ctc_cli_out("get panel ports error\n");
        return CLI_ERROR;
    }

    if (!loop)
    {
        sal_memset(&led_mapping_rst, 0, sizeof(ctc_chip_mac_led_mapping_t));
        led_mapping_rst.port_list = mem_malloc(MEM_CLI_MODULE, max_port_num * sizeof(uint16));
        if (NULL == led_mapping_rst.port_list)
        {
            return CLI_ERROR;
        }
        sal_memset(led_mapping_rst.port_list, 0, max_port_num * sizeof(uint16));
    }
    if (led_mapping_rst.mac_led_num >= max_port_num)
    {
        mem_free(led_mapping_rst.port_list);
        return CLI_ERROR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("lport");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("lport-id", led_mapping_rst.port_list[loop], argv[index + 1]);
    }
    loop++;
    led_mapping_rst.mac_led_num++;
    led_mapping_rst.lport_en = 1;
    index = CTC_CLI_GET_ARGC_INDEX("end");
    if (0xFF != index)
    {
        is_end = 1;
    }
    if (is_end)
    {
        ret = ctcs_chip_set_mac_led_mapping(g_api_lchip, &led_mapping_rst);
        mem_free(led_mapping_rst.port_list);
        loop = 0;
        if (CLI_SUCCESS != ret)
        {
            ctc_cli_out("set mac led mapping error\n");
            return CLI_ERROR;
        }
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_chip_gpio_operation,
        ctc_cli_asw_chip_gpio_operation_cmd,
        "chip gpio gpio-id GPIO_ID (mode MODE | output VALUE | input)",
        "Chip module",
        "Gpio",
        "Gpio id",
        "<0-15>",
        "Gpio mode",
        "0:input 1:output 2:special function[GB only] 3:edge intr input 4:level intr input",
        "Output value",
        "0-1",
        "Input value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint8 gpio_id = 0;
    uint8 value = 0;

    CTC_CLI_GET_UINT8_RANGE("gpio-id", gpio_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("mode", value , argv[index + 1]);
        ret = ctcs_chip_set_gpio_mode(g_api_lchip, gpio_id, value);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("output");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("output", value , argv[index + 1]);
        ret = ctcs_chip_set_gpio_output(g_api_lchip, gpio_id, value);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("input");
    if (0xFF != index)
    {

        ret = ctcs_chip_get_gpio_input(g_api_lchip, gpio_id, &value);
        if (ret < 0)
        {
            ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        ctc_cli_out("GPIO %d Input Signal %u \n", gpio_id, value);
    }

    return ret;

}

CTC_CLI(ctc_cli_asw_chip_io_wr_dis,
        ctc_cli_asw_chip_reg_io_dis_cmd,
        "chip io write (enable | disable) ",
        "Chip module",
        "IO",
        "Write",
        "enable",
        "disable")
{
    int32 ret       = CLI_SUCCESS;
    uint32 enable = 0;

    if (CLI_CLI_STR_EQUAL("enable", 0))
    {
        enable = FALSE;
    }
    else
    {
        enable = TRUE;
    }

    ret = ctcs_chip_set_property(g_api_lchip, CTC_CHIP_PROP_IO_WR_DIS, (void*)&enable);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_io_wr_dis_get,
        ctc_cli_asw_chip_reg_io_dis_get_cmd,
        "show chip io-wr-dis  ",
        "debug show",
        "Chip module",
        "IO write disable")
{
    int32 ret       = CLI_SUCCESS;
    uint32 enable = 0;

    ret = ctcs_chip_get_property(g_api_lchip, CTC_CHIP_PROP_IO_WR_DIS, (void*)&enable);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("%-34s:  %s\n", "Register write disable", enable?"enable":"disable");

    return ret;
}


CTC_CLI(ctc_cli_asw_chip_set_serdes_def,
        ctc_cli_asw_chip_set_serdes_def_cmd,
        "chip serdes SERDES dfe (mode VALUE)",
        "Chip module",
        "Serdes",
        "Serdes id",
        "Dfe",
        "Mode",
        "Value:0:<10inch;1:10inch;2:20inch")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_cfg_t p_dfe;
    uint8 index = 0;

    sal_memset(&p_dfe, 0, sizeof(ctc_chip_serdes_cfg_t));

    CTC_CLI_GET_UINT8("serdes", p_dfe.serdes_id, argv[0]);
    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if(index != 0xFF)
    {
        CTC_CLI_GET_UINT16("mode", p_dfe.value, argv[index+1]);
    }

    ret = ctcs_chip_set_property(g_api_lchip, CTC_CHIP_PROP_SERDES_DFE, (void*)&p_dfe);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_asw_chip_get_serdes_def,
        ctc_cli_asw_chip_get_serdes_def_cmd,
        "show chip serdes SERDES dfe ",
        "Show operate",
        "Chip module",
        "Serdes",
        "Serdes id",
        "dfe")
{
    int32 ret       = CLI_SUCCESS;
    ctc_chip_serdes_cfg_t p_dfe;
    
    sal_memset(&p_dfe, 0, sizeof(ctc_chip_serdes_cfg_t));

    CTC_CLI_GET_UINT8_RANGE("serdes", p_dfe.serdes_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    ctc_cli_out("Show Serdes: 0x%x dfe value\n", p_dfe.serdes_id);
    ctc_cli_out("-------------------------------------------\n");

    ret = ctcs_chip_get_property(g_api_lchip, CTC_CHIP_PROP_SERDES_DFE, (void*)&p_dfe);
    ctc_cli_out("Mode: 0x%x\n", p_dfe.value);
    ctc_cli_out("-------------------------------------------\n");


    return ret;
}

void
_ctc_asw_chip_prbs_event_polling(void* p_data)
{
    uint8 type = 0;
    uint8 is_file = 0;
    uint16 interval = 0;
    char* p_time_str = NULL;
    ctc_chip_serdes_prbs_t prbs_param;
    sal_time_t tv;
    sal_file_t fp = NULL;
    ctc_chip_write_file_t* chip_file_para;
    ctc_vti_t* vty = NULL;
    sal_memset(&prbs_param, 0, sizeof(ctc_chip_serdes_prbs_t));
    
    chip_file_para = (ctc_chip_write_file_t*)p_data;
    prbs_param.serdes_id = chip_file_para->serdes_id;
    interval = chip_file_para->interval;
    prbs_param.mode = 0;
    vty = chip_file_para->p_vty;
    type = CTC_CHIP_PROP_SERDES_PRBS;
    sal_time(&tv);
    p_time_str = sal_ctime(&tv);
    ctc_cli_out("Prbs check monitor begin, %s\n", p_time_str);
    if(*(chip_file_para->file))
    {
        is_file = 1;
        fp = sal_fopen((char*)(chip_file_para->file), "w+");
        if (NULL == fp)
        {
            return;
        }
    }
    while (1)
    {
        if (1 == monitor_polling_task.task_end)
        {
            break;
        }
        (void)ctcs_chip_get_property(g_api_lchip, type, (void*)&prbs_param);
        if (is_file)
        {
            sal_fprintf(fp, "%-34s:  %u\n", "Serdes_id", prbs_param.serdes_id);
            sal_fprintf(fp, "%-34s:  %u\n", "Error_cnt", prbs_param.error_cnt);
            sal_time(&tv);
            p_time_str = sal_ctime(&tv);
            if (!prbs_param.error_cnt)
            {
                sal_fprintf(fp, "prbs check success end, %s\n", p_time_str);
            }
            else
            {
                sal_fprintf(fp, "prbs check error and stop, %s\n", p_time_str);
                break;
            }
        }
        else
        {
            ctc_cli_out("----------------------------\n");
            ctc_cli_out("%-34s:  %u\n", "Serdes_id", prbs_param.serdes_id);
            ctc_cli_out("%-34s:  %u\n", "Error_cnt", prbs_param.error_cnt);
            ctc_cli_out("----------------------------\n");
            sal_time(&tv);
            p_time_str = sal_ctime(&tv);
            if (!prbs_param.error_cnt)
            {
                ctc_cli_out("prbs check success end, %s\n", p_time_str);
            }
            else
            {
                ctc_cli_out("prbs check error and stop, %s\n", p_time_str);
                break;
            }
        }
        sal_task_sleep(interval);
    }
    if (is_file)
    {
        sal_fclose(fp);
        fp = NULL;
    }

}


CTC_CLI(ctc_cli_asw_chip_prbs_polling,
        ctc_cli_asw_chip_prbs_polling_cmd,
        "chip serdes SERDES prbs rx (enable monitor INTERNAL (file FILE_NAME|)|disable monitor)",
        "chip module",
        "serdes",
        "serdes id",
        "prbs",
        "rx",
        "enable",
        "monitor(ms)",
        "internal",
        "file",
        "file name",
        "disable",
        "monitor(ms)")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint32 serdes_id = 0;
    char buffer[SAL_TASK_MAX_NAME_LEN]={0};
    uint16 interval = 0;
    ctc_chip_write_file_t *chip_file_para;

    MALLOC_ZERO(MEM_CLI_MODULE, chip_file_para, sizeof(ctc_chip_write_file_t));
    CTC_CLI_GET_UINT8("serdes", serdes_id, argv[0]);
    if (serdes_id > (MAX_SERDES_NUM -1))
    {
        ctc_cli_out("%% ret = %d, %s \n", CTC_E_INVALID_PARAM, ctc_get_error_desc(CTC_E_INVALID_PARAM));
        return CLI_ERROR;
    }
    chip_file_para->p_vty = vty;
    index = CTC_CLI_GET_ARGC_INDEX("disable");
    if(index != 0xFF)
    {
        if (monitor_polling_task.monitor_task)
        {
            monitor_polling_task.task_end = 1;
            sal_task_destroy(monitor_polling_task.monitor_task);
            monitor_polling_task.monitor_task = NULL;
        }
        mem_free(chip_file_para);
        return CLI_SUCCESS;
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if(index != 0xFF)
    {
        CTC_CLI_GET_UINT16("internal", interval, argv[index+2]);
        index = CTC_CLI_GET_ARGC_INDEX("file");
        if (index != 0xFF)
        {
            sal_strncpy((char*)(chip_file_para->file), argv[index + 1], (MAX_FILE_NAME_SIZE - 1));
        }
        monitor_polling_task.task_end = 0;
        if (NULL == monitor_polling_task.monitor_task)
        {
            sal_sprintf(buffer, "Serdes-Prbs-%d", g_api_lchip);
            chip_file_para->serdes_id = serdes_id;
            chip_file_para->interval =interval;
            ret = sal_task_create(&(monitor_polling_task.monitor_task), buffer,
                                  SAL_DEF_TASK_STACK_SIZE, SAL_TASK_PRIO_DEF, _ctc_asw_chip_prbs_event_polling, (void*)chip_file_para);
            if (ret < 0)
            {
                mem_free(chip_file_para);
                return CTC_E_NOT_INIT;
            }
        }
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_chip_show_device_info,
        ctc_cli_asw_chip_show_device_info_cmd,
        "show chip device information ",
        CTC_CLI_SHOW_STR,
        "Chip module",
        "Device",
        "Information")
{
    ctc_chip_device_info_t device_info;
    int32 ret = 0;
    sal_memset(&device_info, 0, sizeof(device_info));

    ret = ctcs_chip_get_property(g_api_lchip, CTC_CHIP_PROP_DEVICE_INFO, (void*)&device_info);

    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("Chip name: %s, Device Id: %d, Version Id: %d \n", device_info.chip_name, device_info.device_id, device_info.version_id);

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_asw_l3if_set_router_mac,
        ctc_cli_asw_l3if_set_router_mac_cmd,
        "l3if router-mac MAC",
        "L3 interface module",
        "System Router mac",
        CTC_CLI_MAC_FORMAT)
{
    mac_addr_t mac_addr;
    int32 ret = 0;

    sal_memset(&mac_addr, 0, sizeof(mac_addr_t));

    /*parse MAC address */

    CTC_CLI_GET_MAC_ADDRESS("mac address", mac_addr, argv[0]);

    ret = ctcs_l3if_set_router_mac(g_api_lchip, mac_addr);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_l3if_show_router_mac,
        ctc_cli_asw_l3if_show_router_mac_cmd,
        "show l3if router-mac",
        CTC_CLI_SHOW_STR,
        "L3 interface module",
        "Router mac")
{
    int32 ret = 0;
    mac_addr_t mac_addr;

    sal_memset(&mac_addr, 0, sizeof(mac_addr_t));
    ret = ctcs_l3if_get_router_mac(g_api_lchip, mac_addr);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("The router mac is :%.2x%.2x.%.2x%.2x.%.2x%.2x \n",
            mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);


    return ret;
}

CTC_CLI(ctc_cli_asw_chip_set_global_config,
        ctc_cli_asw_chip_set_global_config_cmd,
        "chip global-cfg (discard-macsa-zero | discard-mcast-macsa) (value VALUE)",
        "Chip module",
        "Global config",
        "Discard macsa zero",
        "Discard mcast macsa",
        "Value")
{
    int32 ret = CLI_SUCCESS;
    uint32 value = 0;
    uint8 index = 0;

    index = CTC_CLI_GET_ARGC_INDEX("value");
    if (index != 0xFF)
    {        
        CTC_CLI_GET_UINT32("value", value, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("discard-macsa-zero");
    if (0xFF != index)
    {
        ret = ctcs_global_ctl_set(g_api_lchip, CTC_GLOBAL_DISCARD_MACSA_0_PKT, &value);
    }
    index = CTC_CLI_GET_ARGC_INDEX("discard-mcast-macsa");
    if (0xFF != index)
    {
        ret = ctcs_global_ctl_set(g_api_lchip, CTC_GLOBAL_DISCARD_MCAST_SA_PKT, &value);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_asw_chip_get_global_config,
        ctc_cli_asw_chip_get_global_config_cmd,
        "show chip global-cfg (discard-macsa-zero | discard-mcast-macsa)",
        "Show"
        "Chip module",
        "Global config",
        "Discard macsa zero",
        "Discard mcast macsa",
        "Value")
{
    int32 ret = CLI_SUCCESS;
    uint32 value = 0;
    uint8 index = 0;

    index = CTC_CLI_GET_ARGC_INDEX("discard-macsa-zero");
    if (0xFF != index)
    {
        ret = ctcs_global_ctl_get(g_api_lchip, CTC_GLOBAL_DISCARD_MACSA_0_PKT, &value);
        ctc_cli_out("discard mac sa zero learning :%d\n", value);
    }
    index = CTC_CLI_GET_ARGC_INDEX("discard-mcast-macsa");
    if (0xFF != index)
    {
        ret = ctcs_global_ctl_get(g_api_lchip, CTC_GLOBAL_DISCARD_MCAST_SA_PKT, &value);
        ctc_cli_out("discard sa is mcast :%d\n", value);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

int32
ctc_asw_chip_cli_init(uint8 cli_tree_mode)
{
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_chip_clock_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_mac_led_clock_frequency_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_mac_led_clock_frequency_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_gport_property_prop_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_set_serdes_loopback_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_serdes_prbs_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_serdes_ffe_param_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_read_serdes_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_write_serdes_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_get_serdes_prop_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_set_ipmc_config_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_ipmc_config_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_set_acl_config_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_acl_config_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_mdio_read_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_mdio_write_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_mac_led_en_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_mac_led_mode_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_mac_led_mapping_set_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_gpio_operation_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_reg_io_dis_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_reg_io_dis_get_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_set_serdes_def_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_get_serdes_def_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_prbs_polling_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_show_device_info_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_l3if_set_router_mac_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_l3if_show_router_mac_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_set_global_config_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_chip_get_global_config_cmd);

    return 0;
}

